<?php

namespace App\Controller\Admin;

use App\Controller\AbstractController;
use App\Dao\NavDao;
use App\Dao\SetDao;
use App\Kernel\Util\JwtInstance;
use App\Service\SysService;
use Hyperf\Di\Annotation\Inject;

class NavController extends AbstractController
{
    /**
     * @Inject()
     * @var NavDao
     */
    private $navDao;



    /**
     * 获得
     */
    public function getList()
    {

        try {
            $navs = $this->navDao->getList($this->request->all());
            return $this->response->success('获得成功', $navs);

        } catch (\Exception $e) {
            return $this->response->error($e->getMessage());
        }
    }

    public function upload()
    {
        $file = $this->request->file('file');
        if(!$this->request->hasFile('file'))  return $this->response->error('文件不存在');
        if(!$file->isValid())  return $this->response->error('文件无效');

        $ext = $file->getExtension();
        if(!in_array($ext, explode(',', "jpg,jpeg,png,gif,bmp4'"))) return $this->response->error('文件类型不允许');
        $dirname = date('Ymd');
        if (!file_exists('./upload/'.$dirname)) {
            mkdir($dirname, 0777, true);
        }
        $fileSaveName    =  $dirname. '/' . md5(uniqid()) . "." . $ext;
        $file->moveTo('./upload/'.$fileSaveName);
        $urlPrefix = config('url_prefix');
        if ($file->isMoved()) {
            return $this->response->success('上传成功',[
                'url' => $urlPrefix.'/upload/'.$fileSaveName
            ]);
        }else{
            return $this->response->error('存储失败');
        }

    }
}